package com.novelastudios.utils
{
	/**
	 * Really, I'm going to need to create a getSubFileType or rethink that whole thing.
	 * @author johnbailey ©2009
	 * 
	 */	
	public class FileExtensionUtil
	{		
		public static const PDF		: String	= "pdf";
		public static const DOC		: String	= "word_document";
		public static const PPT		: String	= "powerpoint";
		
		public static const IMAGE	: String 	= "image";
		public static const AUDIO 	: String	= "audio";
		public static const VIDEO	: String 	= "video";
		public static const FLASH	: String	= "flash";
		public static const XML		: String	= "xml";
		public static const UNKNOWN : String	= "unknown";
		public static const CSS		: String 	= "stylesheet";
		
		public static const SPREADSHEET		: String = "spreadsheet";
		public static const VIEWABLE_PAGE	: String = "viewable_page";
		
		/**
		 * @param value The file (location and/or-just name)
		 * @return The file type
		 */ 
		public static function getFileType(value:String):String
		{
			var ext:String = FileExtensionUtil.getFileExtention(value);
			switch(ext)
			{
				case "gif":
				case "jpg":
				case "png":
					return IMAGE;
					break;
				
				case "swf":
					return FLASH;
					break;
				
				case "xls":
				case "xlsx":
					return SPREADSHEET;
					break;
				
				case "pdf":
					return PDF;
					break;
				
				case "ppt":
				case "pptx":
					return PPT;
					break;
				
				case "doc":
				case "docx":
					return DOC;
					break;
				
				case "mp3":
					return AUDIO;
					break;
				
				case "flv":
					return VIDEO;
					break;
				
				case "html":
				case "htm":
					return VIEWABLE_PAGE;
					break;
				
				case "xml":
					return XML;
					break;
				
				case "css":
					return CSS;
					break;
				
				default:
					return UNKNOWN;
					break;
			}
		}
		/**
		 * @param value The file (location and/or-just name with extention)
		 * @return The file extension
		 */ 
		public static function getFileExtention(value:String):String
		{
			if(!StringUtil.isViable(value)) 
				return value;
			
			value = value.replace(/'/g,"");
			value = value.replace(/"/g,"");
			
			var ext_pattern:RegExp = /[\w|\d]+$/;
			var ext:String = value.match(ext_pattern).toString().toLowerCase();
			return ext;
		}
		/**
		 * @param value The file (location and/or-just name)
		 * @return The boolean of whether the file is possibly an animation file type (ie swf)
		 */
		public static function isAnimationType(value:String):Boolean
		{
			var ext:String = FileExtensionUtil.getFileExtention(value);
			switch(ext)
			{
				case "swf":
					return true;
					break;
				default:
					return false;
					break;	
			}
		} 
		
	}
}